// pages/ChoiceShop/ChoiceShop.js
import {
  getShops
} from '../../../utils/networkRequest.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    choiceList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let self = this;
    wx.getLocation({
      type: 'wgs84',
      success: function(res) {
        let location = res.latitude + "," + res.longitude
        getShops(location, (r) => {
          if (r.code == 0) {
            self.setData({
              choiceList: r.data
            })
          } else {
            wx.showToast({
              icon: "none",
              title: r.message,
            })
          }
        })
      }
    })

  },
  //选择门店
  onCheckShop: function(e) {
    let item = e.currentTarget.dataset.item
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面 
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      checkChopInfo: item, 
    })
    wx.navigateBack();
  }
})